#################################################################################
# Filename: 2_round2_figs.R
# Description: Takes the cleaned round 2 data and creates: 
# - Figures 1,2,3,5 in main text
# - Figures A4, A5, A7, A8, A9, A11 in Appendix C
#################################################################################

### Load library dependencies 
library(tidyverse)
library(broom)
library(DeclareDesign)
library(estimatr)
library(rio)
library(ggplot2)
library(gridExtra)

# Import cleaned data from 1_round2_loaddata
dat <- import("Round_2_clean.Rdata") 

# ggplot theme
theme_bw1 <- function(base_size = 16, base_family = "") {
  theme_bw(base_size = base_size, base_family = base_family) %+replace%
    theme(
      axis.text.x =       element_text(size = base_size, colour = "black",  hjust = .5 , vjust=1),
      axis.text.y =       element_text(size = base_size , colour = "black", hjust = 0 , vjust=.5 ), # changes position of X axis text
      axis.ticks =        element_line(colour = "grey50"),
      #   axis.title.y =      element_text(size = base_size,angle=90,vjust=.01,hjust=.1),
      legend.position = "none"
    )
}



#################################################################################
# (1) Creating round 2 figures in main text 
#################################################################################

# Figure 1 right panel
# Outcome: anger
# Comaprison groups: placebo / social media video / tv drama

japan <- data.frame(condition=as.character(dat$clip), Y=dat$Q19_1)
#japan <- japan[!japan$condition=="HK",]
japan$condition <- as.factor(japan$condition)
levels(japan$condition) <- c("Anti-US\nSocial Media Video", "Anti-Japan\nTelevision Drama", "Placebo\nNature Video")
japan$condition <- relevel(japan$condition, "Placebo\nNature Video")

summary_df <-
  japan %>%
  group_by(condition) %>%
  do(tidy(lm_robust(Y ~ 1, data = .))) %>%
  mutate(Y = estimate)

pdf("r2_anger.pdf")
ggplot(summary_df, aes(condition, Y)) +
  geom_point(size = 5, col="blue") +
  geom_errorbar(aes(ymin = conf.low, ymax = conf.high), width = 0, size=1.5, col="blue") +
  theme_bw1() +
  scale_y_continuous(breaks = seq(2.4, 4.6, length.out = 12)) +
  coord_cartesian(ylim = c(2.5, 4.25)) +
  theme(axis.title.x = element_blank()) +
  ylab("Outcome: Anger [1=No anger... 5=Extremely strong anger]")
dev.off()


# Figure 2 upper-right panel
# outcome: anti-japanese sentiment index
# comparison groups: placebo video, tv drama 

japan <- data.frame(condition=as.character(dat$clip), Y=dat$antiforeign_japan_pca)
japan <- japan[!japan$condition=="HK",]
japan$condition <- as.factor(japan$condition)
japan$condition <- droplevels(japan)$condition # elaine
levels(japan$condition) <- c("Anti-Japan\nTelevision Drama", "Placebo\nNature Video")
japan$condition <- relevel(japan$condition, "Placebo\nNature Video")

summary_df <-
  japan %>%
  group_by(condition) %>%
  do(tidy(lm_robust(Y ~ 1, data = .))) %>%
  mutate(Y = estimate)

pdf("r2_japan_antiforeign.pdf")
ggplot(summary_df, aes(condition, Y)) +
  geom_point(size = 3, col="blue") +
  geom_errorbar(aes(ymin = conf.low, ymax = conf.high), width = 0, size=1.5, col="blue") +
  theme_bw1() +
  scale_y_continuous(breaks = seq(-1, 1, length.out = 11)) +
  coord_cartesian(ylim = c(-0.4, 0.4)) +
  theme(axis.title.x = element_blank()) +
  ylab("Outcome: Anti-Japanese sentiment index")
dev.off()

# Figure 2 lower-right panel
# Outcome: anti-American sentiment
# Comparison groups: placebo video, social media video 

hk <- data.frame(condition=as.character(dat$clip), Y=dat$antiforeign_usa_pca)
hk <- hk[!hk$condition=="Japan",]
hk$condition <- as.factor(hk$condition)
hk$condition <- droplevels(hk)$condition # elaine
levels(hk$condition) <- c("Anti-American\nSocial Media Video",  "Placebo\nNature Video")
hk$condition <- relevel(hk$condition, "Placebo\nNature Video")

summary_df <-
  hk %>%
  group_by(condition) %>%
  do(tidy(lm_robust(Y ~ 1, data = .))) %>%
  mutate(Y = estimate)

pdf("r2_hk_antiforeign.pdf")
ggplot(summary_df, aes(condition, Y)) +
  geom_point(size = 5, col="blue") +
  geom_errorbar(aes(ymin = conf.low, ymax = conf.high), width = 0, size=1.5, col="blue") +
  theme_bw1() +
  scale_y_continuous(breaks = seq(-0.4, 0.4, length.out = 11)) +
  coord_cartesian(ylim = c(-0.4, 0.4)) +
  theme(axis.title.x = element_blank()) +
  ylab("Outcome: Anti-American sentiment index")
dev.off()



### Figure 3 (persistence effects)

# upper right: anti-American sentiment
# comparison groups: placebo, social media video 
hk <- data.frame(condition=as.character(dat$clip[which(dat$recontact.lag<8)]), Y=dat$antiforeign_usa_pca_f[which(dat$recontact.lag<8)])
hk <- hk[!hk$condition=="Japan",]
hk$condition <- as.factor(hk$condition)
hk$condition <- droplevels(hk)$condition
levels(hk$condition) <- c("Anti-American\nSocial Media Video", "Placebo\nNature Video")
hk$condition <- relevel(hk$condition, "Placebo\nNature Video")

summary_df <-
  hk %>%
  group_by(condition) %>%
  do(tidy(lm_robust(Y ~ 1, data = .))) %>%
  mutate(Y = estimate)

pdf("r3_hk_antiforeign.pdf")
ggplot(summary_df, aes(condition, Y)) +
  geom_point(size = 5, col="blue") +
  geom_errorbar(aes(ymin = conf.low, ymax = conf.high), width = 0, size=1.5, col="blue") +
  theme_bw1() +
  scale_y_continuous(breaks = seq(-0.4, 0.4, length.out = 11)) +
  coord_cartesian(ylim = c(-0.4, 0.4)) +
  theme(axis.title.x = element_blank()) +
  ylab("Outcome: Anti-American sentiment index")
dev.off()


# bottom right: anger
# comparison groups: placebo, social media video 
hk <- data.frame(condition=as.character(dat$clip[which(dat$recontact.lag<8)]), Y=dat$Q19_1_f[which(dat$recontact.lag<8)])
hk <- hk[!hk$condition=="Japan",]
hk$condition <- as.factor(hk$condition)
hk$condition <- droplevels(hk)$condition
levels(hk$condition) <- c("Anti-American\nSocial Media Video", "Placebo\nNature Video")
hk$condition <- relevel(hk$condition, "Placebo\nNature Video")

summary_df <-
  hk %>%
  group_by(condition) %>%
  do(tidy(lm_robust(Y ~ 1, data = .))) %>%
  mutate(Y = estimate)

pdf("r3_hk_anger.pdf")
ggplot(summary_df, aes(condition, Y)) +
  
  geom_point(size = 5, col="blue") +
  geom_errorbar(aes(ymin = conf.low, ymax = conf.high), width = 0, size=1.5, col="blue") +
  theme_bw1() +
  scale_y_continuous(breaks = seq(1.25, 2.75, length.out = 11)) +
  coord_cartesian(ylim = c(1.25, 2.75)) +
  theme(axis.title.x = element_blank()) +
  ylab("Outcome: Anger [1=No anger... 5=Extremely strong anger]")
dev.off()



# upper left: anti-japanese sentiment index
# comparison groups: placebo, tv drama
japan <- data.frame(condition=as.character(dat$clip[which(dat$recontact.lag<8)]), Y=dat$antiforeign_japan_pca_f[which(dat$recontact.lag<8)])
japan <- japan[!japan$condition=="HK",]
japan$condition <- as.factor(japan$condition)
japan$condition <- droplevels(japan)$condition
levels(japan$condition) <- c("Anti-Japan\nTelevision Drama", "Placebo\nNature Video")
japan$condition <- relevel(japan$condition, "Placebo\nNature Video")

summary_df <-
  japan %>%
  group_by(condition) %>%
  do(tidy(lm_robust(Y ~ 1, data = .))) %>%
  mutate(Y = estimate)

pdf("r3_japan_antiforeign.pdf")
ggplot(summary_df, aes(condition, Y)) +
  geom_point(size = 5, col="blue") +
  geom_errorbar(aes(ymin = conf.low, ymax = conf.high), width = 0, size=1.5, col="blue") +
  theme_bw1() +
  scale_y_continuous(breaks = seq(-0.4, 0.4, length.out = 11)) +
  coord_cartesian(ylim = c(-0.4, 0.4)) +
  theme(axis.title.x = element_blank()) +
  ylab("Outcome: Anti-Japanese sentiment index")
dev.off()


# bottom left: anger
# placebo / tv drama 
japan <- data.frame(condition=as.character(dat$clip[which(dat$recontact.lag<8)]), Y=dat$Q19_1_f[which(dat$recontact.lag<8)])
japan <- japan[!japan$condition=="HK",]
japan$condition <- as.factor(japan$condition)
japan$condition <- droplevels(japan)$condition
levels(japan$condition) <- c( "Anti-Japan\nTelevision Drama", "Placebo\nNature Video")
japan$condition <- relevel(japan$condition, "Placebo\nNature Video")


summary_df <-
  japan %>%
  group_by(condition) %>%
  do(tidy(lm_robust(Y ~ 1, data = .))) %>%
  mutate(Y = estimate)

pdf("r3_japan_anger.pdf")
ggplot(summary_df, aes(condition, Y)) +
  geom_point(size = 5, col="blue") +
  geom_errorbar(aes(ymin = conf.low, ymax = conf.high), width = 0, size=1.5, col="blue") +
  theme_bw1() +
  scale_y_continuous(breaks = seq(1.25, 2.75, length.out = 11)) +
  coord_cartesian(ylim = c(1.25, 2.75)) +
  theme(axis.title.x = element_blank()) +
  ylab("Outcome: Anger [1=No anger... 5=Extremely strong anger]")
dev.off()


# Figure 5 
# Outcome: would protest poor govt services
# Comparison groups: placebo video, social media video, tv drama 
japan <- data.frame(condition=as.character(dat$clip), Y=dat$protest.gov)
japan$condition <- as.factor(japan$condition)
japan$condition <- droplevels(japan)$condition
levels(japan$condition) <- c("Anti-American\nSocial Media Video", "Anti-Japan\nTelevision Drama", "Placebo\nNature Video")
japan$condition <- relevel(japan$condition, "Placebo\nNature Video")

summary_df <-
  japan %>%
  group_by(condition) %>%
  do(tidy(lm_robust(Y ~ 1, data = .))) %>%
  mutate(Y = estimate)

pdf("r2_gov_protest.pdf")
ggplot(summary_df, aes(condition, Y)) +
  geom_point(size = 5, col="blue") +
  geom_errorbar(aes(ymin = conf.low, ymax = conf.high), width = 0, size=1.5, col="blue") +
  theme_bw1() +
  scale_y_continuous(breaks = seq(0.1, 0.35, length.out = 6)) +
  coord_cartesian(ylim = c(0.15, 0.35)) +
  theme(axis.title.x = element_blank()) +
  ylab("Outcome: Would protest poor government services [1=yes, 0=no]")
dev.off()






#################################################################################
# (2) Creating round 2 figures in Appendix C
#################################################################################

# Figure A4 - Effect on perceptions of govt service provision

hk <- data.frame(condition=as.character(dat$clip), Y=dat$Q68)
hk$condition <- as.factor(hk$condition)
levels(hk$condition) <- c("Anti-American\nSocial Media Video", "Anti-Japan\nTelevision Drama", "Placebo\nNature Video")
hk$condition <- relevel(hk$condition, "Placebo\nNature Video")

summary_df <-
  hk %>%
  group_by(condition) %>%
  do(tidy(lm_robust(Y ~ 1, data = .))) %>%
  mutate(Y = estimate)

pdf("r2_services.pdf")
ggplot(summary_df, aes(condition, Y)) +
  geom_point(size = 5, col="blue") +
  geom_errorbar(aes(ymin = conf.low, ymax = conf.high), width = 0, size=1.5, col="blue") +
  theme_bw1() +
  scale_y_continuous(breaks = seq(3.75, 4.5, length.out = 11)) +
  coord_cartesian(ylim = c(3.75, 4.5)) +
  theme(axis.title.x = element_blank()) +
  ylab("Level of satisfaction")
dev.off()


# Figure A5, bottom panel 

# (left figure) outcome: Patriotism index 
# comparison groups: placebo video, social media video, tv drama 

japan <- data.frame(condition=as.character(dat$clip), Y=dat$patriot_pca)
japan$condition <- as.factor(japan$condition)
japan$condition <- droplevels(japan)$condition
levels(japan$condition) <- c("Anti-American\nSocial Media Video", "Anti-Japan\nTelevision Drama", "Placebo\nNature Video")
japan$condition <- relevel(japan$condition, "Placebo\nNature Video")

summary_df <-
  japan %>%
  group_by(condition) %>%
  do(tidy(lm_robust(Y ~ 1, data = .))) %>%
  mutate(Y = estimate)

pdf("r2_patriotic.pdf")
ggplot(summary_df, aes(condition, Y)) +
  geom_point(size = 3, col="blue") +
  geom_errorbar(aes(ymin = conf.low, ymax = conf.high), width = 0, size=1.5, col="blue") +
  theme_bw1() +
  scale_y_continuous(breaks = seq(-1, 1, length.out = 11)) +
  coord_cartesian(ylim = c(-0.5, 0.5)) +
  theme(axis.title.x = element_blank()) +
  ylab("Outcome: Patriotism index")
dev.off()


# (right figure) outcome: Hawkishness index
# comparison groups: placebo video, social media video, tv drama 
japan <- data.frame(condition=as.character(dat$clip), Y=dat$militant_pca)
japan$condition <- as.factor(japan$condition)
levels(japan$condition) <- c("Anti-American\nSocial Media Video", "Anti-Japan\nTelevision Drama", "Placebo\nNature Video")
japan$condition <- relevel(japan$condition, "Placebo\nNature Video")

summary_df <-
  japan %>%
  group_by(condition) %>%
  do(tidy(lm_robust(Y ~ 1, data = .))) %>%
  mutate(Y = estimate)

pdf("r2_hawkish.pdf")
ggplot(summary_df, aes(condition, Y)) +
  geom_point(size = 3, col="blue") +
  geom_errorbar(aes(ymin = conf.low, ymax = conf.high), width = 0, size=1.5, col="blue") +
  theme_bw1() +
  scale_y_continuous(breaks = seq(-1, 1, length.out = 11)) +
  coord_cartesian(ylim = c(-0.5, 0.5)) +
  theme(axis.title.x = element_blank()) +
  ylab("Outcome: Hawkishness index")
dev.off()


# Figure A7, top panel (R2 questions comprising Anti-Japanese sentiment index)

pdf("r2_anti_foreign_japan_questions.pdf", width=12, height=7.5)
par(mfrow = c(1,2),
    oma=c(1,1,0, 0) ,
    mar=c(4,1,4, 1) )


plot(1, xlim=c(-0.6, 0.6), ylim=c(1, 6), axes=F,  xlab="")


text(y = 6:1, x= 0.6,par("usr")[1], labels =  c("The Japanese government has not\nsufficiently apologized to China", 
                                                "Chinese leaders should quickly\ndispatch troops to the Diaoyu islands",
                                                "Japanese people are violent",
                                                "Japanese people are untrustworthy",
                                                "Japanese people are rule-following",
                                                "Japanese people are true\nto their word"), 
     srt = 0, pos = 2, xpd = TRUE, cex=1.9)





test1 <-  t.test(dat$Q25[dat$clip=="Japan"], dat$Q25[dat$clip=="placebo"])
test2 <-  t.test(dat$Q26[dat$clip=="Japan"], dat$Q26[dat$clip=="placebo"])
test3 <-  t.test(dat$Q54_1[dat$clip=="Japan"], dat$Q54_1[dat$clip=="placebo"])
test4 <-  t.test(dat$Q54_2[dat$clip=="Japan"], dat$Q54_2[dat$clip=="placebo"])
test5 <-  t.test(dat$Q54_3[dat$clip=="Japan"], dat$Q54_3[dat$clip=="placebo"])
test6 <-  t.test(dat$Q54_4[dat$clip=="Japan"], dat$Q54_4[dat$clip=="placebo"])



plot(100, pch=16, xlim=c(-1, 1), ylim=c(1, 6), col="black", xlab="Anti-Japan TV drama", ylab="", yaxt= "n", cex.lab=1.6) 
abline(v=0, col="darkgray", lwd=2)

segments(test1$conf.int[1], 6, test1$conf.int[2], 6, col= 'black', lwd=3)
segments(test2$conf.int[1], 5, test2$conf.int[2], 5, col= 'black', lwd=3)
segments(test3$conf.int[1], 4, test3$conf.int[2], 4, col= 'black', lwd=3)
segments(test4$conf.int[1],3, test4$conf.int[2], 3,  col= 'black', lwd=3)
segments(test5$conf.int[1], 2, test5$conf.int[2], 2, col= 'black', lwd=3)
segments(test6$conf.int[1], 1, test6$conf.int[2], 1, col= 'black', lwd=3)

points(test1$estimate[1]-test1$estimate[2], 6, pch=16, col= 'black', cex=2)
points(test2$estimate[1]-test2$estimate[2], 5, pch=16, col= 'black', cex=2)
points(test3$estimate[1]-test3$estimate[2], 4, pch=16, col= 'black', cex=2)
points(test4$estimate[1]-test4$estimate[2], 3, pch=16, col= 'black', cex=2)
points(test5$estimate[1]-test5$estimate[2], 2, pch=16, col= 'black', cex=2)
points(test6$estimate[1]-test6$estimate[2], 1, pch=16, col= 'black', cex=2)

dev.off()



# Figure A7, bottom panel (R2 questions comprising Anti-American sentiment index)

pdf("r2_anti_foreign_usa_questions.pdf", width=12, height=7.5)
par(mfrow = c(1,2),
    oma=c(1,1,0, 0) ,
    mar=c(4,1,4, 1) )

plot(1, xlim=c(-0.6, 0.6), ylim=c(1, 6), axes=F,  xlab="")


text(y = 6:1, x= 0.6,par("usr")[1], labels =  c("Western countries are\nresponsible for HK protests", 
                                                "Foreign countries have\nviolated China's sovereinty",
                                                "American people are violent",
                                                "American people are untrustworthy",
                                                "American people are rule-following",
                                                "American people are true\nto their word"), 
     srt = 0, pos = 2, xpd = TRUE, cex=1.9)

test1 <-  t.test(dat$Q69[dat$clip=="HK"], dat$Q69[dat$clip=="placebo"])
test2 <-  t.test(dat$Q70[dat$clip=="HK"], dat$Q70[dat$clip=="placebo"])
test3 <-  t.test(dat$Q65_1[dat$clip=="HK"], dat$Q65_1[dat$clip=="placebo"])
test4 <-  t.test(dat$Q65_2[dat$clip=="HK"], dat$Q65_2[dat$clip=="placebo"])
test5 <-  t.test(dat$Q65_3[dat$clip=="HK"], dat$Q65_3[dat$clip=="placebo"])
test6 <-  t.test(dat$Q65_4[dat$clip=="HK"], dat$Q65_4[dat$clip=="placebo"])


plot(100, pch=16, xlim=c(-1, 1), ylim=c(1, 6), col="black", xlab="Anti-US social media clip", ylab="", yaxt= "n", cex.lab=1.6) 
abline(v=0, col="darkgray", lwd=2)

segments(test1$conf.int[1], 6, test1$conf.int[2], 6, col= 'black', lwd=3)
segments(test2$conf.int[1], 5, test2$conf.int[2], 5, col= 'black', lwd=3)
segments(test3$conf.int[1], 4, test3$conf.int[2], 4, col= 'black', lwd=3)
segments(test4$conf.int[1],3, test4$conf.int[2], 3,  col= 'black', lwd=3)
segments(test5$conf.int[1], 2, test5$conf.int[2], 2, col= 'black', lwd=3)
segments(test6$conf.int[1], 1, test6$conf.int[2], 1, col= 'black', lwd=3)

points(test1$estimate[1]-test1$estimate[2], 6, pch=16, col= 'black', cex=2)
points(test2$estimate[1]-test2$estimate[2], 5, pch=16, col= 'black', cex=2)
points(test3$estimate[1]-test3$estimate[2], 4, pch=16, col= 'black', cex=2)
points(test4$estimate[1]-test4$estimate[2], 3, pch=16, col= 'black', cex=2)
points(test5$estimate[1]-test5$estimate[2], 2, pch=16, col= 'black', cex=2)
points(test6$estimate[1]-test6$estimate[2], 1, pch=16, col= 'black', cex=2)


dev.off()



# Figure A8, top panel (Round 3, questions comprising Anti-Japanese sentiment index)

pdf("r3_anti_foreign_japan_questions.pdf", width=12, height=7.5)
par(mfrow = c(1,2),
    oma=c(1,1,0, 0) ,
    mar=c(4,1,4, 1) )


plot(1, xlim=c(-0.6, 0.6), ylim=c(1, 6), axes=F,  xlab="")


text(y = 6:1, x= 0.6,par("usr")[1], labels =  c("The Japanese government has not\nsufficiently apologized to China", 
                                                "Chinese leaders should quickly\ndispatch troops to the Diaoyu islands",
                                                "Japanese people are violent",
                                                "Japanese people are untrustworthy",
                                                "Japanese people are rule-following",
                                                "Japanese people are true\nto their word"), 
     srt = 0, pos = 2, xpd = TRUE, cex=1.9)


test1 <-  t.test(dat$Q25_f[dat$clip=="Japan"], dat$Q25_f[dat$clip=="placebo"])
test2 <-  t.test(dat$Q26_f[dat$clip=="Japan"], dat$Q26_f[dat$clip=="placebo"])
test3 <-  t.test(dat$Q54_1_f[dat$clip=="Japan"], dat$Q54_1_f[dat$clip=="placebo"])
test4 <-  t.test(dat$Q54_2_f[dat$clip=="Japan"], dat$Q54_2_f[dat$clip=="placebo"])
test5 <-  t.test(dat$Q54_3_f[dat$clip=="Japan"], dat$Q54_3_f[dat$clip=="placebo"])
test6 <-  t.test(dat$Q54_4_f[dat$clip=="Japan"], dat$Q54_4_f[dat$clip=="placebo"])

plot(100, pch=16, xlim=c(-1, 1), ylim=c(1, 6), col="black", xlab="Anti-Japan TV drama", ylab="", yaxt= "n", cex.lab=1.6) 
abline(v=0, col="darkgray", lwd=2)

segments(test1$conf.int[1], 6, test1$conf.int[2], 6, col= 'black', lwd=3)
segments(test2$conf.int[1], 5, test2$conf.int[2], 5, col= 'black', lwd=3)
segments(test3$conf.int[1], 4, test3$conf.int[2], 4, col= 'black', lwd=3)
segments(test4$conf.int[1],3, test4$conf.int[2], 3,  col= 'black', lwd=3)
segments(test5$conf.int[1], 2, test5$conf.int[2], 2, col= 'black', lwd=3)
segments(test6$conf.int[1], 1, test6$conf.int[2], 1, col= 'black', lwd=3)

points(test1$estimate[1]-test1$estimate[2], 6, pch=16, col= 'black', cex=2)
points(test2$estimate[1]-test2$estimate[2], 5, pch=16, col= 'black', cex=2)
points(test3$estimate[1]-test3$estimate[2], 4, pch=16, col= 'black', cex=2)
points(test4$estimate[1]-test4$estimate[2], 3, pch=16, col= 'black', cex=2)
points(test5$estimate[1]-test5$estimate[2], 2, pch=16, col= 'black', cex=2)
points(test6$estimate[1]-test6$estimate[2], 1, pch=16, col= 'black', cex=2)

dev.off()

# Figure A8 bottom panel (R3, anti-American sentiment questions)

pdf("r3_anti_foreign_usa_questions.pdf", width=12, height=7.5)
par(mfrow = c(1,2),
    oma=c(1,1,0, 0) ,
    mar=c(4,1,4, 1) )

plot(1, xlim=c(-0.6, 0.6), ylim=c(1, 6), axes=F,  xlab="")


text(y = 6:1, x= 0.6,par("usr")[1], labels =  c("Western countries are\nresponsible for HK protests", 
                                                "Foreign countries have\nviolated China's sovereignty",
                                                "American people are violent",
                                                "American people are untrustworthy",
                                                "American people are rule-following",
                                                "American people are true\nto their word"), 
     srt = 0, pos = 2, xpd = TRUE, cex=1.9)


test1 <-  t.test(dat$Q69_f[dat$clip=="HK"], dat$Q69_f[dat$clip=="placebo"])
test2 <-  t.test(dat$Q70_f[dat$clip=="HK"], dat$Q70_f[dat$clip=="placebo"])
test3 <-  t.test(dat$Q65_1_f[dat$clip=="HK"], dat$Q65_1_f[dat$clip=="placebo"])
test4 <-  t.test(dat$Q65_2_f[dat$clip=="HK"], dat$Q65_2_f[dat$clip=="placebo"])
test5 <-  t.test(dat$Q65_3_f[dat$clip=="HK"], dat$Q65_3_f[dat$clip=="placebo"])
test6 <-  t.test(dat$Q65_4_f[dat$clip=="HK"], dat$Q65_4_f[dat$clip=="placebo"])


plot(100, pch=16, xlim=c(-1, 1), ylim=c(1, 6), col="black", xlab="Anti-US social media clip", ylab="", yaxt= "n", cex.lab=1.6) 
abline(v=0, col="darkgray", lwd=2)

segments(test1$conf.int[1], 6, test1$conf.int[2], 6, col= 'black', lwd=3)
segments(test2$conf.int[1], 5, test2$conf.int[2], 5, col= 'black', lwd=3)
segments(test3$conf.int[1], 4, test3$conf.int[2], 4, col= 'black', lwd=3)
segments(test4$conf.int[1],3, test4$conf.int[2], 3,  col= 'black', lwd=3)
segments(test5$conf.int[1], 2, test5$conf.int[2], 2, col= 'black', lwd=3)
segments(test6$conf.int[1], 1, test6$conf.int[2], 1, col= 'black', lwd=3)

points(test1$estimate[1]-test1$estimate[2], 6, pch=16, col= 'black', cex=2)
points(test2$estimate[1]-test2$estimate[2], 5, pch=16, col= 'black', cex=2)
points(test3$estimate[1]-test3$estimate[2], 4, pch=16, col= 'black', cex=2)
points(test4$estimate[1]-test4$estimate[2], 3, pch=16, col= 'black', cex=2)
points(test5$estimate[1]-test5$estimate[2], 2, pch=16, col= 'black', cex=2)
points(test6$estimate[1]-test6$estimate[2], 1, pch=16, col= 'black', cex=2)

dev.off()




# Figure A9: Questions comrpising Patriotism and Hawkishness indices

# R2: Patriotism (top)
pdf("r2_patriotism_questions.pdf", width=14, height=3.5)
par(mfrow = c(1,3),
    oma=c(1,1,0, 0) ,
    mar=c(4,1,4, 1) )

plot(1, xlim=c(-0.6, 0.6), ylim=c(1, 4), axes=F,  xlab="")


text(y = 4:1, x= 0.6,par("usr")[1], labels =  c("I would prefer to be\na Chinese citizen",
                                                "Chinese people are warlike",
                                                "Chinese people are rule-following",
                                                "Chinese people are true\nto their word"), 
     srt = 0, pos = 2, xpd = TRUE, cex=1.9)

test1 <-  t.test(dat$Q53[dat$clip=="Japan"], dat$Q53[dat$clip=="placebo"])
test2 <-  t.test(dat$Q56_1[dat$clip=="Japan"], dat$Q56_1[dat$clip=="placebo"])
test3 <-  t.test(dat$Q56_2[dat$clip=="Japan"], dat$Q56_2[dat$clip=="placebo"])
test4 <-  t.test(dat$Q56_3[dat$clip=="Japan"], dat$Q56_3[dat$clip=="placebo"])


plot(100, pch=16, xlim=c(-1, 1), ylim=c(1, 4), col="black", xlab="Anti-Japan TV drama", ylab="", yaxt= "n", cex.lab=1.6) 
abline(v=0, col="darkgray", lwd=2)

segments(test1$conf.int[1], 4, test1$conf.int[2], 4, col= 'black', lwd=3)
segments(test2$conf.int[1], 3, test2$conf.int[2], 3, col= 'black', lwd=3)
segments(test3$conf.int[1], 2, test3$conf.int[2], 2, col= 'black', lwd=3)
segments(test4$conf.int[1],1, test4$conf.int[2], 1,  col= 'black', lwd=3)

points(test1$estimate[1]-test1$estimate[2], 4, pch=16, col= 'black', cex=2)
points(test2$estimate[1]-test2$estimate[2], 3, pch=16, col= 'black', cex=2)
points(test3$estimate[1]-test3$estimate[2], 2, pch=16, col= 'black', cex=2)
points(test4$estimate[1]-test4$estimate[2], 1, pch=16, col= 'black', cex=2)


test1 <-  t.test(dat$Q53[dat$clip=="HK"], dat$Q53[dat$clip=="placebo"])
test2 <-  t.test(dat$Q56_1[dat$clip=="HK"], dat$Q56_1[dat$clip=="placebo"])
test3 <-  t.test(dat$Q56_2[dat$clip=="HK"], dat$Q56_2[dat$clip=="placebo"])
test4 <-  t.test(dat$Q56_3[dat$clip=="HK"], dat$Q56_3[dat$clip=="placebo"])


plot(100, pch=16, xlim=c(-1, 1), ylim=c(1, 4), col="black", xlab="Anti-US social media clip", ylab="", yaxt= "n", cex.lab=1.6) 
abline(v=0, col="darkgray", lwd=2)

segments(test1$conf.int[1], 4, test1$conf.int[2], 4, col= 'black', lwd=3)
segments(test2$conf.int[1], 3, test2$conf.int[2], 3, col= 'black', lwd=3)
segments(test3$conf.int[1], 2, test3$conf.int[2], 2, col= 'black', lwd=3)
segments(test4$conf.int[1],1, test4$conf.int[2], 1,  col= 'black', lwd=3)

points(test1$estimate[1]-test1$estimate[2], 4, pch=16, col= 'black', cex=2)
points(test2$estimate[1]-test2$estimate[2], 3, pch=16, col= 'black', cex=2)
points(test3$estimate[1]-test3$estimate[2], 2, pch=16, col= 'black', cex=2)
points(test4$estimate[1]-test4$estimate[2], 1, pch=16, col= 'black', cex=2)
dev.off()


# R2: Hawkishness (second from top)
pdf("r2_hawkish_questions.pdf", width=14, height=3)
par(mfrow = c(1,3),
    oma=c(1,1,0, 0) ,
    mar=c(4,1,4, 1) )

plot(1, xlim=c(-0.6, 0.6), ylim=c(1, 3), axes=F,  xlab="")


text(y = 3:1, x= 0.6,par("usr")[1], labels =  c("China should increase\nnational defense spending",
                                                "Chinese leaders should quickly\ndispatch troops to the Diaoyu islands",
                                                "The best way to ensure China's\nsecurity is to increase military strength"), 
     srt = 0, pos = 2, xpd = TRUE, cex=1.9)


test1 <-  t.test(dat$Q28[dat$clip=="Japan"], dat$Q28[dat$clip=="placebo"])
test2 <-  t.test(dat$Q26[dat$clip=="Japan"], dat$Q26[dat$clip=="placebo"])
test3 <-  t.test(dat$Q52[dat$clip=="Japan"], dat$Q52[dat$clip=="placebo"])


plot(100, pch=16, xlim=c(-1, 1), ylim=c(1, 3), col="black", xlab="Anti-Japan TV drama", ylab="", yaxt= "n", cex.lab=1.6) 
abline(v=0, col="darkgray", lwd=2)



segments(test1$conf.int[1], 3, test1$conf.int[2], 3, col= 'black', lwd=3)
segments(test2$conf.int[1], 2, test2$conf.int[2], 2, col= 'black', lwd=3)
segments(test3$conf.int[1], 1, test3$conf.int[2], 1, col= 'black', lwd=3)

points(test1$estimate[1]-test1$estimate[2], 3, pch=16, col= 'black', cex=2)
points(test2$estimate[1]-test2$estimate[2], 2, pch=16, col= 'black', cex=2)
points(test3$estimate[1]-test3$estimate[2], 1, pch=16, col= 'black', cex=2)



test1 <-  t.test(dat$Q28[dat$clip=="HK"], dat$Q28[dat$clip=="placebo"])
test2 <-  t.test(dat$Q26[dat$clip=="HK"], dat$Q26[dat$clip=="placebo"])
test3 <-  t.test(dat$Q52[dat$clip=="HK"], dat$Q52[dat$clip=="placebo"])


plot(100, pch=16, xlim=c(-1, 1), ylim=c(1, 3), col="black", xlab="Anti-US social media clip", ylab="", yaxt= "n", cex.lab=1.6) 
abline(v=0, col="darkgray", lwd=2)

segments(test1$conf.int[1], 3, test1$conf.int[2], 3, col= 'black', lwd=3)
segments(test2$conf.int[1], 2, test2$conf.int[2], 2, col= 'black', lwd=3)
segments(test3$conf.int[1], 1, test3$conf.int[2], 1, col= 'black', lwd=3)

points(test1$estimate[1]-test1$estimate[2], 3, pch=16, col= 'black', cex=2)
points(test2$estimate[1]-test2$estimate[2], 2, pch=16, col= 'black', cex=2)
points(test3$estimate[1]-test3$estimate[2], 1, pch=16, col= 'black', cex=2)

dev.off()

# R3: Patriotism (third from top)
pdf("r3_patriotism_questions.pdf", width=14, height=3.5)
par(mfrow = c(1,3),
    oma=c(1,1,0, 0) ,
    mar=c(4,1,4, 1) )

plot(1, xlim=c(-0.6, 0.6), ylim=c(1, 4), axes=F,  xlab="")


text(y = 4:1, x= 0.6,par("usr")[1], labels =  c("I would prefer to be\na Chinese citizen",
                                                "Chinese people are warlike",
                                                "Chinese people are rule-following",
                                                "Chinese people are true\nto their word"), 
     srt = 0, pos = 2, xpd = TRUE, cex=1.9)

test1 <-  t.test(dat$Q53_f[dat$clip=="Japan"], dat$Q53_f[dat$clip=="placebo"])
test2 <-  t.test(dat$Q56_1_f[dat$clip=="Japan"], dat$Q56_1_f[dat$clip=="placebo"])
test3 <-  t.test(dat$Q56_2_f[dat$clip=="Japan"], dat$Q56_2_f[dat$clip=="placebo"])
test4 <-  t.test(dat$Q56_3_f[dat$clip=="Japan"], dat$Q56_3_f[dat$clip=="placebo"])


plot(100, pch=16, xlim=c(-1, 1), ylim=c(1, 4), col="black", xlab="Anti-Japan TV drama", ylab="", yaxt= "n", cex.lab=1.6) 
abline(v=0, col="darkgray", lwd=2)

segments(test1$conf.int[1], 4, test1$conf.int[2], 4, col= 'black', lwd=3)
segments(test2$conf.int[1], 3, test2$conf.int[2], 3, col= 'black', lwd=3)
segments(test3$conf.int[1], 2, test3$conf.int[2], 2, col= 'black', lwd=3)
segments(test4$conf.int[1],1, test4$conf.int[2], 1,  col= 'black', lwd=3)

points(test1$estimate[1]-test1$estimate[2], 4, pch=16, col= 'black', cex=2)
points(test2$estimate[1]-test2$estimate[2], 3, pch=16, col= 'black', cex=2)
points(test3$estimate[1]-test3$estimate[2], 2, pch=16, col= 'black', cex=2)
points(test4$estimate[1]-test4$estimate[2], 1, pch=16, col= 'black', cex=2)

test1 <-  t.test(dat$Q53_f[dat$clip=="Anti-American\nSocial Media Video"], dat$Q53_f[dat$clip=="placebo"])
test2 <-  t.test(dat$Q56_1_f[dat$clip=="Anti-American\nSocial Media Video"], dat$Q56_1_f[dat$clip=="placebo"])
test3 <-  t.test(dat$Q56_2_f[dat$clip=="Anti-American\nSocial Media Video"], dat$Q56_2_f[dat$clip=="placebo"])
test4 <-  t.test(dat$Q56_3_f[dat$clip=="Anti-American\nSocial Media Video"], dat$Q56_3_f[dat$clip=="placebo"])


plot(100, pch=16, xlim=c(-1, 1), ylim=c(1, 4), col="black", xlab="Anti-US social media clip", ylab="", yaxt= "n", cex.lab=1.6) 
abline(v=0, col="darkgray", lwd=2)

segments(test1$conf.int[1], 4, test1$conf.int[2], 4, col= 'black', lwd=3)
segments(test2$conf.int[1], 3, test2$conf.int[2], 3, col= 'black', lwd=3)
segments(test3$conf.int[1], 2, test3$conf.int[2], 2, col= 'black', lwd=3)
segments(test4$conf.int[1],1, test4$conf.int[2], 1,  col= 'black', lwd=3)

points(test1$estimate[1]-test1$estimate[2], 4, pch=16, col= 'black', cex=2)
points(test2$estimate[1]-test2$estimate[2], 3, pch=16, col= 'black', cex=2)
points(test3$estimate[1]-test3$estimate[2], 2, pch=16, col= 'black', cex=2)
points(test4$estimate[1]-test4$estimate[2], 1, pch=16, col= 'black', cex=2)
dev.off()



 #R3: Hawkishness (bototm)

pdf("r3_hawkish_questions.pdf", width=14, height=3)
par(mfrow = c(1,3),
    oma=c(1,1,0, 0) ,
    mar=c(4,1,4, 1) )

plot(1, xlim=c(-0.6, 0.6), ylim=c(1, 3), axes=F,  xlab="")

text(y = 3:1, x= 0.6,par("usr")[1], labels =  c("China should increase\nnational defense spending",
                                                "Chinese leaders should quickly\ndispatch troops to the Diaoyu islands",
                                                "The best way to ensure China's\nsecurity is to increase military strength"), 
     srt = 0, pos = 2, xpd = TRUE, cex=1.9)


test1 <-  t.test(dat$Q28_f[dat$clip=="Japan"], dat$Q28_f[dat$clip=="placebo"])
test2 <-  t.test(dat$Q26_f[dat$clip=="Japan"], dat$Q26_f[dat$clip=="placebo"])
test3 <-  t.test(dat$Q52_f[dat$clip=="Japan"], dat$Q52_f[dat$clip=="placebo"])


plot(100, pch=16, xlim=c(-1, 1), ylim=c(1, 3), col="black", xlab="Anti-Japan TV drama", ylab="", yaxt= "n", cex.lab=1.6) 
abline(v=0, col="darkgray", lwd=2)

segments(test1$conf.int[1], 3, test1$conf.int[2], 3, col= 'black', lwd=3)
segments(test2$conf.int[1], 2, test2$conf.int[2], 2, col= 'black', lwd=3)
segments(test3$conf.int[1], 1, test3$conf.int[2], 1, col= 'black', lwd=3)

points(test1$estimate[1]-test1$estimate[2], 3, pch=16, col= 'black', cex=2)
points(test2$estimate[1]-test2$estimate[2], 2, pch=16, col= 'black', cex=2)
points(test3$estimate[1]-test3$estimate[2], 1, pch=16, col= 'black', cex=2)

test1 <-  t.test(dat$Q28_f[dat$clip=="HK"], dat$Q28_f[dat$clip=="placebo"])
test2 <-  t.test(dat$Q26_f[dat$clip=="HK"], dat$Q26_f[dat$clip=="placebo"])
test3 <-  t.test(dat$Q52_f[dat$clip=="HK"], dat$Q52_f[dat$clip=="placebo"])


plot(100, pch=16, xlim=c(-1, 1), ylim=c(1, 3), col="black", xlab="Anti-US social media clip", ylab="", yaxt= "n", cex.lab=1.6) 
abline(v=0, col="darkgray", lwd=2)


segments(test1$conf.int[1], 3, test1$conf.int[2], 3, col= 'black', lwd=3)
segments(test2$conf.int[1], 2, test2$conf.int[2], 2, col= 'black', lwd=3)
segments(test3$conf.int[1], 1, test3$conf.int[2], 1, col= 'black', lwd=3)

points(test1$estimate[1]-test1$estimate[2], 3, pch=16, col= 'black', cex=2)
points(test2$estimate[1]-test2$estimate[2], 2, pch=16, col= 'black', cex=2)
points(test3$estimate[1]-test3$estimate[2], 1, pch=16, col= 'black', cex=2)

dev.off()



# Figure A11 

# Happiness
japan <- data.frame(condition=as.character(dat$clip), Y=dat$Q19_3)
#japan <- japan[!japan$condition=="HK",]
japan$condition <- as.factor(japan$condition)
levels(japan$condition) <- c("American interference\nin HK video", "Anti-Japan\ntelevision drama", "Placebo\nnature video")
japan$condition <- relevel(japan$condition, "Placebo\nnature video")

summary_df <-
  japan %>%
  group_by(condition) %>%
  do(tidy(lm_robust(Y ~ 1, data = .))) %>%
  mutate(Y = estimate)

pdf("r2_happy.pdf")
ggplot(summary_df, aes(condition, Y)) +
  geom_point(
    data = japan,
    position = position_jitter(width = 0.2, height = 0.1),
    alpha = 0.05
  ) +
  geom_point(size = 5, col="red") +
  geom_errorbar(aes(ymin = conf.low, ymax = conf.high), width = 0, size=1.5, col="red") +
  theme_bw1() +
  scale_y_continuous(breaks = seq(1, 5, length.out = 5)) +
  coord_cartesian(ylim = c(0.9, 5.1)) +
  theme(axis.title.x = element_blank()) +
  ylab("Outcome: Happiness [1=No happiness...5=Extremely strong happiness]")
dev.off()


#Pride
japan <- data.frame(condition=as.character(dat$clip), Y=dat$Q19_4)
#japan <- japan[!japan$condition=="HK",]
japan$condition <- as.factor(japan$condition)
levels(japan$condition) <- c("American interference\nin HK video", "Anti-Japan\ntelevision drama", "Placebo\nnature video")
japan$condition <- relevel(japan$condition, "Placebo\nnature video")

summary_df <-
  japan %>%
  group_by(condition) %>%
  do(tidy(lm_robust(Y ~ 1, data = .))) %>%
  mutate(Y = estimate)

pdf("r2_proud.pdf")
ggplot(summary_df, aes(condition, Y)) +
  geom_point(
    data = japan,
    position = position_jitter(width = 0.2, height = 0.1),
    alpha = 0.05
  ) +
  geom_point(size = 5, col="red") +
  geom_errorbar(aes(ymin = conf.low, ymax = conf.high), width = 0, size=1.5, col="red") +
  theme_bw1() +
  scale_y_continuous(breaks = seq(1, 5, length.out = 5)) +
  coord_cartesian(ylim = c(0.9, 5.1)) +
  theme(axis.title.x = element_blank()) +
  ylab("Outcome: Pride [1=No pride...5=Extremely strong pride]")
dev.off()

#Sadness

japan <- data.frame(condition=as.character(dat$clip), Y=dat$Q19_2)
#japan <- japan[!japan$condition=="HK",]
japan$condition <- as.factor(japan$condition)
levels(japan$condition) <- c("American interference\nin HK video", "Anti-Japan\ntelevision drama", "Placebo\nnature video")
japan$condition <- relevel(japan$condition, "Placebo\nnature video")

summary_df <-
  japan %>%
  group_by(condition) %>%
  do(tidy(lm_robust(Y ~ 1, data = .))) %>%
  mutate(Y = estimate)

pdf("r2_sadness.pdf")
ggplot(summary_df, aes(condition, Y)) +
  geom_point(
    data = japan,
    position = position_jitter(width = 0.2, height = 0.1),
    alpha = 0.05
  ) +
  geom_point(size = 5, col="red") +
  geom_errorbar(aes(ymin = conf.low, ymax = conf.high), width = 0, size=1.5, col="red") +
  theme_bw1() +
  scale_y_continuous(breaks = seq(1, 5, length.out = 5)) +
  coord_cartesian(ylim = c(0.9, 5.1)) +
  theme(axis.title.x = element_blank()) +
  ylab("Outcome: Sad [1=No sadness... 5=Extremely strong sadness]")
dev.off()



